//
//  AlertCustomView.m
//  JLG
//
//  Created by  程 强 on 15/8/4.
//  Copyright (c) 2015年 cl. All rights reserved.
//

#import "AlertCustomView.h"
#import "JTCSM.h"

@implementation AlertCustomView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
//@"你要发布什么类型的吐槽呢?"
- (id)initWithFrame:(CGRect)frame titleContent:(NSString *)text leftBtnTitle:(NSString *)leftText rightBtnTitle:(NSString *)rightText{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:.5];
        self.userInteractionEnabled = YES;
        CGFloat height = 150;
        CGFloat spacing = 40;
        
        UIView *backView = [[UIView alloc]initWithFrame:CGRectMake(spacing, (frame.size.height-height)/2-30, frame.size.width-2*spacing, height)];
        backView.backgroundColor =RGBACOLOR(255, 255, 255, .8);
        backView.userInteractionEnabled = YES;
        backView.layer.masksToBounds = YES;
        backView.layer.cornerRadius = 3;
        [self addSubview:backView];
        
        
        CGFloat btnWidth = 180;
        CGFloat btnSpacing = (backView.frame.size.width - btnWidth )/2;
        CGFloat btnY  = 30;
        UIButton *leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [leftBtn setTitle:leftText forState:UIControlStateNormal];
        leftBtn.layer.masksToBounds = YES;
        leftBtn.layer.cornerRadius = 3;
        [leftBtn setBackgroundColor:RGBACOLOR(241,141,0,1)];
        leftBtn.showsTouchWhenHighlighted = YES;
        [leftBtn setFrame:CGRectMake(btnSpacing,btnY, btnWidth, 35)];
        [leftBtn addTarget:self action:@selector(leftBtnAction) forControlEvents:UIControlEventTouchUpInside];
        [backView addSubview:leftBtn];

        
        UIButton *rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [rightBtn setTitle:rightText forState:UIControlStateNormal];
        rightBtn.layer.masksToBounds = YES;
        rightBtn.layer.cornerRadius = 3;
        [rightBtn setBackgroundColor:RGBACOLOR(241,141,0,1)];
        rightBtn.showsTouchWhenHighlighted = YES;
        [rightBtn setFrame:CGRectMake(btnSpacing,btnY+15+leftBtn.frame.size.height, btnWidth, 35)];
        [rightBtn addTarget:self action:@selector(rightBtnAction) forControlEvents:UIControlEventTouchUpInside];
        [backView addSubview:rightBtn];

        
    }
    return self;
}
- (void)leftBtnAction{
    [_delegate selectLeftButton];
}

-(void)rightBtnAction{
    [_delegate selectRightButton];
}

//- (void)closeAlertview{
//    [_delegate selectCloseButton];
//}
@end
